//
//  JFAlertTextView.m
//  JFKit
//
//  Created by Alan Wang on 2020/3/14.
//  Copyright © 2020 Alan Wang. All rights reserved.
//

#import "JFAlertTextView.h"
#import "JFKitPri.h"
@interface JFAlertTextView()<UITextViewDelegate>

@end

@implementation JFAlertTextView

-(instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        [self buildUI];
    }
    return self;
}
-(void)buildUI{
    [self addView];
    [self layoutView];
    [self configStyle];
}
-(void)addView{
     UITextView * tempLab = [UITextView AW_TextView:^(UITextView *view) {
         view.textColor = AWThemeColorForKey(@"Global.navTintColor");
         view.textAlignment = NSTextAlignmentCenter;
         view.font = JFScalePingFangFont(14);
         view.backgroundColor = [UIColor clearColor];
                   
     }];
     tempLab.editable = NO;
    self.textView = tempLab;
    self.textView.delegate = self;
    self.textView.linkTextAttributes = @{NSForegroundColorAttributeName : HexColor(@"#3A72EF"),NSFontAttributeName:JFScalePingFangFont(14)};
    [self addSubview:self.textView];
    
}
-(void)layoutView{
    AWMasFast(self.textView, {
        AWMasTop(self, 0)
        AWMasBottom(self, 0)
        AWMasLeft(self, 0)
        AWMasRight(self, 0)
    })
}
-(void)configStyle{
    self.backgroundColor = [UIColor clearColor];
}

#pragma mark--辅助方法
- (BOOL)textView:(UITextView *)textView shouldInteractWithURL:(NSURL *)URL inRange:(NSRange)characterRange {
    if ([URL.scheme isEqualToString:@"Alan"]) {
        NSString *selectStr = [textView.text substringWithRange:characterRange];
        if (self.textBlock) {
            self.textBlock(selectStr);
        }
        return NO;
    }
    return YES;
}


#pragma mark--懒加载

@end
